<?php
include("../../tools/session.php");
include("../../tools/controls.php");

// 如果登录失败、无权限访问，那么采取相应措施
if (!($is_login_success === true)) { session_hop_page("../index.php"); exit(); }
if (!power_check(0)) { include("tpl-inc-wp.php"); $tpl->display($oa_tpl_path . "/no-power.html"); exit(); }

include("../../tools/mysql.php");
db_connect();

# 从 session 中获取的用户 ID 和 用户名
$session_user_id = $_SESSION["user"]["id"];
$session_user_name = $_SESSION["user"]["username"];

$username		= $_POST["username"];
$password		= $_POST["password"];
$job_num		= $_POST["job_num"];
$company_id	= $_POST["company_id"];
$section_id		= $_POST["section_id"];
$office_id		= $_POST["office_id"];
$position_id		= $_POST["position_id"];
$group_id		= $_POST["group_id"];
// $is_master		= $_POST["is_master"];
$power_add		= $_POST["power_add"];
$power_trim	= $_POST["power_trim"];
$identity		= $_POST["identity"];
$sex			= $_POST["sex"];
$birth			= $_POST["birth"];
$tel				= $_POST["tel"];
$phone			= $_POST["phone"];
$qq				= $_POST["qq"];
$email			= $_POST["email"];
$address		= $_POST["address"];	
$marriage		= $_POST["marriage"];
$culture		= $_POST["culture"];
$degree			= $_POST["degree"];
$diploma_num	= $_POST["diploma_num"];
$graduate		= $_POST["graduate"];
$school			= $_POST["school"];
$spec_field		= $_POST["spec_field"];
$job_q_c		= $_POST["job_q_c"];
$grade			= $_POST["grade"];
$census_reg	= $_POST["census_reg"];
$census_class	= $_POST["census_class"];

/* $sql_user = "INSERT INTO user(username, password, job_num, company_id, section_id, office_id, position_id, group_id, is_master, power_add, power_trim, register_time) "
					. " VALUES('" . $username . "', MD5('" . $password . "'), '" . $job_num . "', " . $company_id . ", " . $section_id . ", " . $office_id . ", "
					. $position_id . ", " . $group_id . ", " . $is_master . ", '" . $power_add . "', '" . $power_trim . "', NOW())"; */
$sql_user = "INSERT INTO user(username, password, job_num, office_id, position_id, group_id, power_add, power_trim, register_time) "
					. " VALUES('" . $username . "', MD5('" . $password . "'), '" . $job_num . "', " . $office_id . ", "
					. $position_id . ", " . $group_id . ", '" . $power_add . "', '" . $power_trim . "', NOW())";
$sql_archive = "INSERT INTO archive(username, identity, sex, birth, tel, phone, qq, email, address, marriage, culture, degree, diploma_num, graduate, school, "
					. "spec_field, job_q_c, grade, census_reg, census_class, register_date) "
					. " VALUES('" . $username . "', '" . $identity . "', " . $sex . ", '" . $birth . "', '" . $tel . "', '" . $phone . "' , '" . $qq . "', '" . $email
					. "', '" . $address . "', " . $marriage . ", '" . $culture . "', '" . $degree . "', '" . $diploma_num . "', '"
					. $graduate . "', '" . $school . "', '" . $spec_field . "', '" . $job_q_c . "', '" . $grade . "', '" . $census_reg
					. "', " . $census_class . ", NOW())";
$db_log_str = "添加用户 " . $username . " 及其档案";
$db_log_error_str = "添加用户 " . $username . " 及其档案失败！";
$sql_log = "INSERT INTO sys_log(user_id, ulogs, log_time) VALUES(" . $session_user_id . ", '" . $db_log_str . "', NOW())";
$sql_log_error = "INSERT INTO sys_log(user_id, ulogs, log_time) VALUES(" . $session_user_id . ", '" . $db_log_error_str . "', NOW())";

// db_exec($sql_user);
// db_exec($sql_archive);


if (db_exec($sql_user) && db_exec($sql_archive))
{
	db_exec($sql_log);
	echo "Success: 添加用户成功！";
}
else
{
	db_exec($sql_log_error);
	echo "Error: 添加用户失败！";
}

?>
